#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    long long beautifulSubarrays(vector<int>& nums) {
        unordered_map<int, int> hash;
        int s = 0;
        long long res = 0;
        hash[0] = 1;
        for (const auto& num : nums)
        {
            s ^= num;
            res += hash[s]++;
        }
        return res;
    }
};